package com.neutech.neusys.controller;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


import com.neutech.neusys.service.UserService;
import com.neutech.po.User;
import com.neutech.vo.ToAddUserVo;

@RestController
//@CrossOrigin("http://localhost:8081")
@RequestMapping("/neusys/user")
public class UserController {
	@Autowired
	private UserService userService;
//	增加用户
//	@param user 用户信息
//	@return 添加成功还是失败 “success”--成功，“error”--失败
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public User addNewUser(@RequestBody Map<String,Object> user){
		System.out.println(user.get("userName"));
		return userService.addNewUser(user);
	}
	//查询用户
	@RequestMapping(value="/queryAllUser")
	public List<User> queryAllUser(){
		return userService.queryAllUser();
	}
	//更新用户
	@RequestMapping(value="/update")
	public String updateUser(@RequestBody User user){
		int result = userService.updateUser(user);
		System.out.println(user.getUserName());
		System.out.println(user.getId());
		if(result > 0){
			return "nice";
		}else{
			return "oh god";
		}
	}
	//删除用户
	@RequestMapping(value="/del")
	public String delUserById(Integer id){
		int result = userService.delUserById(id);
		if(result > 0){
			return "bingo";
		}else{
			return "oh shit";
		}
	}
	/**
	 * 添加用户界面出现，要查询信息，填充下拉列表
	 * @param：user 用户信息
	 * @return添加成功还是失败：“success”--成功，“error”--失败
	 */
	@RequestMapping(value="/toadd")
	public ToAddUserVo toNewUser(){
		return  userService.toAddUser();		
	}
}

